from selenium.webdriver.common.by import By
from base import BasePage, BaseHandle
# from utils import app_swipe_find
from hmAutoTest.utils import UtilsDriver


class IndexPage(BasePage):
    def __init__(self):
        super().__init__()
        self.scroll_element = (By.CLASS_NAME, "android.view.View")
        self.channel = (By.XPATH, "//android.view.View/*[contains(@text, '{}')]")

    def find_scroll_element(self):
        return self.get_element(self.scroll_element)


class IndexHandle(BaseHandle):
    def __init__(self):
        self.index_page = IndexPage()

    def click_channel(self, channel):
        xpath = self.index_page.channel[0].format(channel)
        UtilsDriver.app_swipe_find(self.index_page.driver, self.index_page.find_scroll_element(), xpath)


class IndexProxy:
    def __init__(self):
        self.index_handle = IndexHandle()

    def find_channel(self, channel):
        self.index_handle.click_channel(channel)